<template>
	<view>
		<view class="main" style="margin-top: 4vw;">
			<view class="center_qb t23" style="margin-top: 8vw;">超级管理员信息</view>
			<!-- <view class="center_qb t1">超级管理员需在开户后进行签约，并接收日常重要管理信息和进行资金操作，请确定其为商户法定代表人或负责人。</view> -->
			<view class="shuru">
				<text class="shuru_tit t1">邀请人手机号</text>
				<input type="text" class="shuru_text t1" value="" v-model="invitePhone" placeholder="请输入邀请人手机号" />
			</view>
			<view class="shuru">
				<text class="shuru_tit t1">支付宝账号</text>
				<input type="text" class="shuru_text t1" value="" v-model="aliAdminAccount" placeholder="请输入支付宝账号" />
			</view>
			<!-- <view class="center_qb t13">
				注：此支付宝账号需要满足以下条件：<br>若您的营业执照类型为个体工商户，则该支付宝账号的实名认证信息需要与营业执照法人信息相同；<br>若您的营业执照类型为其他，则该支付宝账号需要已实名认证企业。
			</view> -->
			<!-- <view class="shuru">
				<text class="shuru_tit t1">姓名</text>
				<input type="text" class="shuru_text t1" value="" v-model="name" placeholder="请输入超级管理员姓名" />
			</view>

			<view class="shuru">
				<text class="shuru_tit t1">身份证号</text>
				<input type="text" class="shuru_text t1" value="" v-model="idcard" :placeholder="array1[index]" />
			</view> -->
			<view class="shuru">
				<text class="shuru_tit t1">联系手机</text>
				<input type="number" class="shuru_text t1" value="" v-model="tel" placeholder="请输入联系手机" />
			</view>
			<view class="shuru">
				<text class="shuru_tit t1">联系邮箱</text>
				<input type="text" class="shuru_text t1" value="" v-model="email" placeholder="请输入联系邮箱" />
			</view>
			<!-- #ifdef MP-ALIPAY -->
			<view class="center_qb t13">
				注：此支付宝账号需要满足以下条件：<br>若您的营业执照类型为个体工商户，则该支付宝账号的实名认证信息需要与营业执照法人信息相同；<br>若您的营业执照类型为其他，则该支付宝账号需要已实名认证企业。
			</view>
			<!-- #endif --> 
			<!-- <view class="shuru">
				<text class="shuru_tit t1">选择服务商</text>
				<picker @change="providerPickerChange" :value="zmid" :range="provider" range-key="name" class="shuru_text2">
					<view class="uni-input uni-input1 t1 ">{{provider[providerIndex].name}}</view>
				</picker>
			</view> -->
			<view class="center_qb t13" v-if="strs!=''">错误提示：{{strs}}</view>
		</view>
		<view class="tuic tuic11 t2" @click="zhuanru()">下一步</view>
		<!-- <view class="tuic2 t2" @click="xiugai()" v-if="types==2">修改</view> -->
		<view class="bai"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mainid: '',
				index: 0,
				address: '',
				provider: [{
					id: 1,
					name: "招财阿咪"
				}, {
					id: 2,
					name: "招财阿咪"
				}],
				providerId:'',
				providerIndex:0,

				array: [{
					tit: '超级管理员身份证件号码',
					id: '0'
				}, {
					tit: '超级管理员微信openid',
					id: '1'
				}],
				array1: ['请输入超级管理员身份证件号码', '请输入超级管理员微信openid'],
				zmid: '',
				name: '',
				idcard: '',
				tel: '',
				email: '',
				name1: '',
				idcard1: '',
				tel1: '',
				email1: '',
				types: 1,
				invitePhone: '',
				invitePhone1: '',
				aliAdminAccount: '',
				aliAdminAccount1: '',
				strs: '',
			}
		},
		onLoad() {
			var _this = this;
			uni.getStorage({
				key: 'user',
				success: function(res) {
					_this.mainid = res.data.id;
					_this.info();
				}
			});
			this.getProviderConfig()
		},
		methods: {

			getProviderConfig() {
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/getProviderConfig', //仅为示例，并非真实接口地址。
					method: 'post',
					data: {},
					success: (res) => {
						this.provider = res.data.data
						console.log("多服务商: ", res);
					},
					fail: (error) => {
						console.log("errr: ", error);
						uni.showToast({
							title: error.errMsg,
							icon: 'none',
							duration: 1000
						})
					}
				});
			},

			IdentityCodeValid(code) {
				var city = {
					11: "北京",
					12: "天津",
					13: "河北",
					14: "山西",
					15: "内蒙古",
					21: "辽宁",
					22: "吉林",
					23: "黑龙江 ",
					31: "上海",
					32: "江苏",
					33: "浙江",
					34: "安徽",
					35: "福建",
					36: "江西",
					37: "山东",
					41: "河南",
					42: "湖北 ",
					43: "湖南",
					44: "广东",
					45: "广西",
					46: "海南",
					50: "重庆",
					51: "四川",
					52: "贵州",
					53: "云南",
					54: "西藏 ",
					61: "陕西",
					62: "甘肃",
					63: "青海",
					64: "宁夏",
					65: "新疆",
					71: "台湾",
					81: "香港",
					82: "澳门",
					91: "国外 "
				};
				var tip = "";
				var pass = true;

				if (!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)) {
					tip = "身份证号格式错误";
					pass = false;
				} else if (!city[code.substr(0, 2)]) {
					tip = "地址编码错误";
					pass = false;
				} else {
					//18位身份证需要验证最后一位校验位
					if (code.length == 18) {
						code = code.split('');
						//∑(ai×Wi)(mod 11)
						//加权因子
						var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
						//校验位
						var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
						var sum = 0;
						var ai = 0;
						var wi = 0;
						for (var i = 0; i < 17; i++) {
							ai = code[i];
							wi = factor[i];
							sum += ai * wi;
						}
						var last = parity[sum % 11];
						if (parity[sum % 11] != code[17]) {
							tip = "校验位错误";
							pass = false;
						}
					}
				}
				//if(!pass) alert(tip);
				return pass;
			},

			// tianjia() {

			// 	uni.navigateTo({
			// 		url: '/pages/qianbao/qianbao'
			// 	});
			// },
			
			providerPickerChange(e){
				console.log("providerPickerChange: ",e);
				this.providerIndex = e.detail.value
				this.providerId = this.provider[this.providerIndex].id
			},
			
			bindPickerChange: function(e) {
				var that = this;
				// console.log('picker发送选择改变，携带值为：' + e.detail.value);
				// console.log(e);
				var ii = e.detail.value;
				that.zmid = that.array[ii].id;
				that.index = e.detail.value
			},
			info() {
				var _this = this;
				uni.request({
					header: {
						'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/getSuper/' + _this.mainid, //仅为示例，并非真实接口地址。
					method: 'post',
					data: {
						id: _this.mainid, //	用户ID（mainId）		true	string
					},
					success: (res) => {
						// console.log(res);
						if (res.data.status == '200') {
							if (res.data.data) {
								// console.log(res.data.data);
								_this.types = 2;
								_this.aliAdminAccount = res.data.data.aliAdminAccount;
								_this.invitePhone = res.data.data.invitePhone;
								_this.tel = res.data.data.phone;
								_this.name = res.data.data.name;
								_this.idcard = res.data.data.idCard;
								_this.email = res.data.data.email;
								_this.tel1 = res.data.data.phone;
								_this.name1 = res.data.data.name;
								_this.idcard1 = res.data.data.idCard;
								_this.email1 = res.data.data.email;
								_this.invitePhone1 = res.data.data.invitePhone;
								_this.aliAdminAccount1 = res.data.data.aliAdminAccount;
							}
						}
					},
					fail: (error) => {
						// console.log(error)
					}
				});
			},
			zhuanru() {
				var _this = this;
				_this.types = 1
				if (_this.types == 2) {
					uni.navigateTo({
						url: '/pages/shenqing/shenqing_zhuti'
					});
				} else if (_this.types == 1) {

					// if (_this.checks === false) {
					// 	return false
					// }
					if (!_this.invitePhone) {
						uni.showToast({
							title: '请输入邀请人手机号',
							icon: 'none',
							duration: 2000
						});
						return false
					}
					if (!_this.aliAdminAccount) {
						uni.showToast({
							title: '请输入支付宝账号',
							icon: 'none',
							duration: 2000
						});
						return false
					}
					// if (!_this.name) {
					// 	uni.showToast({
					// 		title: '请输入姓名',
					// 		icon: 'none',
					// 		duration: 2000
					// 	});
					// 	return false
					// }
					// if (!_this.idcard) {
					// 	uni.showToast({
					// 		title: '请输入身份证号码',
					// 		icon: 'none',
					// 		duration: 2000
					// 	});
					// 	return false
					// }
					// var t = _this.IdentityCodeValid(_this.idcard);
					// // console.log(t);
					// if (t == false) {
					// 	uni.showToast({
					// 		title: '身份证号码格式不正确',
					// 		icon: 'none',
					// 		duration: 2000
					// 	});
					// 	return false
					// }
					if (!_this.tel) {
						uni.showToast({
							title: '请输入手机号',
							icon: 'none',
							duration: 2000
						});
						return false
					}
					var pattern = /^1[3456789]\d{9}$/;
					if (!pattern.test(_this.tel)) {
						uni.showToast({
							title: '手机号格式不正确',
							icon: 'none',
							duration: 2000
						});
						return false
					}
					if (!_this.email) {
						uni.showToast({
							title: '请输入邮箱',
							icon: 'none',
							duration: 2000
						});
						return false
					}
					var reg = /^\w+((.\w+)|(-\w+))@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/; //正则表达式
					if (!reg.test(_this.email)) {
						uni.showToast({
							title: '邮箱格式不正确',
							icon: 'none',
							duration: 2000
						});
						return false
					}
					// _this.checks = false
					uni.showLoading();
					// console.log(_this.aliAdminAccount,_this.invitePhone,_this.tel,_this.name,_this.idcard,_this.email,_this.mainid);
					
					let datas= {
						aliAdminAccount: _this.aliAdminAccount,
						inviteCode: _this.invitePhone,
						phone: _this.tel,
						name: _this.name,
						idCard: _this.idcard,
						email: _this.email,
						id: _this.mainid
						// providerId:_this.providerId
					}
					console.log('请求参数1：',datas)
					uni.request({
						header: {
							'Content-Type': 'application/json', //自定义请求头信息
						},
						url: getApp().globalData.url + 'mch/updateSuper', //仅为示例，并非真实接口地址。
						method: 'post',
						data: {
							aliAdminAccount: _this.aliAdminAccount,
							inviteCode: _this.invitePhone,
							phone: _this.tel,
							name: _this.name,
							idCard: _this.idcard,
							email: _this.email,
							id: _this.mainid
							// providerId:_this.providerId
						},
						success: (res) => {
							// _this.checks = true
							console.log('updateSuper:',res);
							uni.hideLoading();
							if (res.data.status == '200') {
								uni.showToast({
									title: '管理员信息提交成功',
									icon: 'none',
									duration: 2000
								});
								setTimeout(function() {
									uni.navigateTo({
										url: '/pages/shenqing/shenqing_zhuti'
									});
								}, 2000)

							} else if (res.data.status == '501') {
								let str = "";
								for (var a in res.data.data) str += res.data.data[a] + ";\n";
								_this.strs = str;
								// uni.showToast({
								// 	title: str,
								// 	icon: 'none',
								// 	duration: 3000
								// });

							} else {

								uni.showToast({
									title: '管理员信息提交失败',
									icon: 'none',
									duration: 2000
								});
							}
						},
						fail: (error) => {
							// _this.checks = true
							uni.hideLoading();

							uni.showToast({
								title: '管理员信息提交失败',
								icon: 'none',
								duration: 2000
							});
						}
					});
				}
			},
			xiugai() {
				var _this = this;

				// if (_this.checks === false) {
				// 	return false
				// }
				// if (_this.invitePhone == _this.invitePhone1 && _this.name == _this.name1 && _this.idcard == _this
				// 	.idcard1 && _this.tel == _this.tel1 && _this.email == _this.email1 && _this.aliAdminAccount == _this
				// 	.aliAdminAccount1) {
				// 	uni.showToast({
				// 		title: '无任何修改',
				// 		icon: 'none',
				// 		duration: 2000
				// 	});
				// 	return false
				// }
				if (!_this.invitePhone) {
					uni.showToast({
						title: '请输入邀请人手机号',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				var pattern = /^1[3456789]\d{9}$/;
				if (!pattern.test(_this.invitePhone)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!_this.aliAdminAccount) {
					uni.showToast({
						title: '请输入支付宝账号',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				// if (!_this.name) {
				// 	uni.showToast({
				// 		title: '请输入姓名',
				// 		icon: 'none',
				// 		duration: 2000
				// 	});
				// 	return false
				// }
				// if (!_this.idcard) {
				// 	uni.showToast({
				// 		title: '请输入身份证号码',
				// 		icon: 'none',
				// 		duration: 2000
				// 	});
				// 	return false
				// }
				// var t = _this.IdentityCodeValid(_this.idcard);
				// // console.log(t);
				// if (t == false) {
				// 	uni.showToast({
				// 		title: '身份证号码格式不正确',
				// 		icon: 'none',
				// 		duration: 2000
				// 	});
				// 	return false
				// }
				if (!_this.tel) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				// var pattern = /^1[3456789]\d{9}$/;
				if (!pattern.test(_this.tel)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				if (!_this.email) {
					uni.showToast({
						title: '请输入邮箱',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				var reg = /^\w+((.\w+)|(-\w+))@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/; //正则表达式
				if (!reg.test(_this.email)) {
					uni.showToast({
						title: '邮箱格式不正确',
						icon: 'none',
						duration: 2000
					});
					return false
				}
				// _this.checks = false
				uni.showLoading();
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: getApp().globalData.url + 'mch/updateSuper', //仅为示例，并非真实接口地址。
					method: 'post',
					data: {
						aliAdminAccount: _this.aliAdminAccount,
						inviteCode: _this.invitePhone,
						phone: _this.tel,
						name: _this.name,
						idCard: _this.idcard,
						email: _this.email,
						id: _this.mainid, //	用户ID（mainId）		true	string
					},
					success: (res) => {
						// console.log(res);
						uni.hideLoading();
						// _this.checks = true;
						if (res.data.status == '200') {
							uni.showToast({
								title: '管理员信息修改成功',
								icon: 'none',
								duration: 2000
							});
							setTimeout(function() {
								uni.navigateTo({
									url: '/pages/shenqing/shenqing_zhuti'
								});
							}, 2000)
						} else if (res.data.status == '501') {
							let str = "";
							for (var a in res.data.data) str += res.data.data[a] + ";\n";
							_this.strs = str;
							// uni.showToast({
							// 	title: str,
							// 	icon: 'none',
							// 	duration: 3000
							// });
						} else {

							uni.showToast({
								title: '管理员信息修改失败',
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: (error) => {
						uni.hideLoading();
						// _this.checks = true;

						uni.showToast({
							title: '管理员信息修改失败',
							icon: 'none',
							duration: 2000
						});
					}
				});
			}
		}
	}
</script>

<style>
	.bai {
		width: 100%;
		height: 30vw;
		display: block;
		float: left;
	}

	.center_qb {
		width: 100%;
		height: auto;
		line-height: 8vw;
		display: block;
		float: left;
		padding: 2vw 0;
	}

	.login_main_li_yzm {
		width: auto;
		height: 8vw;
		display: block;
		float: right;
		background: #fcbe16;
		padding: 0 3vw;
		line-height: 8vw;
		border-radius: 4vw;
	}

	.shuru {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		border-radius: 2vw;
		overflow: hidden;
		padding: 2vw 4vw;
		background: #fff;
		margin-top: 4vw;
		box-shadow: 0px 0px 1vw #ddd;
	}

	.shuru_tit {
		width: 30%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: left;
	}

	.shuru_text {
		width: 60%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: right;
		text-align: right;
	}

	select.shuru_text {
		border: none;
	}



	.baodan_zhu {
		width: 90%;
		height: auto;
		display: block;
		float: left;
		margin: 2vw 5%;
		background: #fff;
		border-radius: 2vw;
		padding: 4vw;
		box-shadow: 0px 0px 1vw #ccc;
		margin-top: 3vw;
	}

	.baodan_tit {
		width: 100%;
		height: 8vw;
		line-height: 8vw;
		display: block;
		float: left;
		text-align: center;
	}

	.baodan_into {
		width: 100%;
		height: auto;
		display: block;
		float: left;
		line-height: 7vw;
		display: block;
		float: left;
		min-height: 40vw;
		background: url(../../static/img/jiaa.png) no-repeat center;
	}

	.baodan_into_image {
		width: 90%;
		height: auto;
		display: block;
		float: left;
		margin: 0 5%;
	}

	.shuru_text1 {
		width: 100%;
		height: 10vw;
		line-height: 10vw;
		display: block;
		float: left;
	}

	.shuru_text2 {
		background: url(../../static/img/turn.png) no-repeat right center;
		background-size: 2vw;
		height: 10vw;
		line-height: 10vw;
		text-align: right;
		padding-right: 4vw;
	}
	.uni-input1{
		height: 10vw;
	}
	.tuic11{
		margin-bottom: 5vw;
	}
</style>
